17. Templates and Different Point Cloud Data

Header Text

Templates and Different Point Cloud Data

ND313 C1 L1 A15 Overview On PCD Types Quiz [LB]

Overview of PCD types

Why Use Templates?

The lidar scan function used previously produced a pcl PointCloud object with pcl::PointXYZ points. The object uses a template because there are many different types of point clouds: some that are 3D, some that are 2D, some that include color and intensity. Here you are working with plain 3D point clouds so PointXYZ is used. However, later in the course you will have points with an intensity component as well.

Instead of defining two separate functions one with an argument for PointXYZ and the other for PointXYZI, templates can automate this process. With templates, you only have to write the function once and use the template like an argument to specify the point type.

Templates and Pointers

If you haven’t used templates with pointers before, you may have noticed in the code that typename is used whenever a pointer is used that depends on a template. For example in the function signature here:

typename pcl::PointCloud<PointT>::Ptr ProcessPointClouds<PointT>::FilterCloud(typename pcl::PointCloud<PointT>::Ptr cloud, float filterRes, Eigen::Vector4f minPoint, Eigen::Vector4f maxPoint)

The reason for this is the following: Given a piece of code with a type name parameter, like pcl::PointCloud<PointT>::Ptr , the compiler is unable to determine if the code is a value or a type without knowing the value for the type name parameter. The compiler will assume that the code represents a value. If the code actually represents a typename, you will need to specify that.

Test your own intuition with the quiz below. You can use this documentation for help.

Using Templates

Is pcl::PointCloud<PointT>::Ptr a value or a type?

SOLUTION: type

Explanation

ND313 C1 L1 A16 Using Templates Solution [LB]